
<!--{include /service/service_head}-->


<!-- End #sidebar -->
	<div id="main-content">
		<!-- Main Content Section with everything -->

		<!-- Page Head -->
		<!-- End .clear -->
		
		<div class="content-box">
			<!-- Start Content Box -->
			<div class="content-box-header">
				<h3>予約追加/変更</h3>
				<ul class="content-box-tabs" style="display:none;">

					<li><a href="#tab1" class="default-tab">详细</a></li>
					<!-- href must be unique and match the id of target div -->
					<li><a href="#tab2">编辑</a></li>
				</ul>
				<div class="clear"></div>
			</div>
			<!-- End .content-box-header -->
			
			<div class="content-box-content">
				<form action="/service/editOrder.php" id="testForm" method="post">
				<input type="hidden" name="id" value="{$orderId}">
				<div class="tab-content default-tab" id="tab1">
					<!-- This is the target div. id must match the href of this div's tab -->
					<div class="table_box">
						<table>
						<tbody>
						<tr>
					      <td class="text_left">予約開始時間：</td>
					      <td>
					        <!--{if $order != null }-->
					        <input type="text" name="start_date" value="${date("Y-m-d H:i", $order['service_start_time'])}" onfocus="WdatePicker({lang:'jp', dateFmt:'yyyy-MM-dd HH:mm', minDate:'${date("Y-m-d H:i")}'})" class="Wdate" ><br/>
					        <!--{else}-->
					        <input type="text" name="start_date" value="${date("Y-m-d H:i")}" onfocus="WdatePicker({lang:'jp', dateFmt:'yyyy-MM-dd HH:mm', minDate:'${date("Y-m-d H:i")}'})" class="Wdate"><br/>
					        <!--{/if}-->
					      </td>
					      <td id="timeError"></td>
					    </tr>
					    <tr>
					      <td class="text_left">予約お客様<!--{if $order['user_id'] < 1  }-->(電話番号)<!--{/if}-->：</td>
					      <td>
					        <!--{if $order['user_id'] > 0 }-->
					        <?php $tempUser = Users::GetUser($order['user_id'])?>
					        {$tempUser['family_name']} {$tempUser['personal_name']}
					        <!--{else}-->
					        <input name="tel_no" type="text" value="{$order['back1']}" size="27"/>
					      </td>
					      <td>　</td>
					    </tr>
					    <tr>
					    	<td class="text_left">お客様：</td>
					    	<td>
					        	<input name="name" type="text" value="{$order['back2']}" size="27"/>
						        <!--<input type="button" id="searchUser" value="search"/>
						        --><input type="hidden" name="user_id"/>
					        <!--{/if}-->
					      </td>
					      <td>&nbsp;</td>
					    </tr>
					    
					    <tr>
					      <td class="text_left">予約店舗：</td>
					      <td>
					        <select name="shopId" class="f-city" style="width:100">
								<option value="0" style="width:40">選択してください</option>
								${Utility::Option(Utility::OptionArray($shopList, 'id', 'shop_name'), $defaultShopId)}
							</select>
					      </td>
					      <td>&nbsp;</td>
					    </tr>
					    <tr>
					      <td class="text_left">予約コース{$serviceId}&nbsp;：</td>
					      <td>
					        <select id="select" name="service_id" class="small-input">
					           	<option value="0">選択してください</option>
								${Utility::Option(Utility::OptionArray($serviceList, 'id', 'service_name'), $serviceId)}
					        </select>
					      </td>
					      <td>&nbsp;</td>
					    </tr>
					    <tr>
					      <td class="text_left">スタッフ指名：</td>
					      <td>
					      		<input type="checkbox" value="1" name="isDesignationed"/>
					      		<select id="designationStuff" name="staff_id" class="small-input">
						           	<option value="0">選択してください</option>
									${Utility::Option(Utility::OptionArray($staffList, 'id', 'family_name', 'personal_name'), $staffId)}
									<option value="99999">Ghost(Designed For Exchange)</option>
					        	</select>
					      </td>
					      <td id="staff_error"></td>
					    </tr>
					    <tr>
					      <td class="text_left">追加項目：</td>
					      <td><input type="checkbox" value="1" name="addExtra"/></td>
					    </tr>
					    
					    <tr id="extraParts" style="display:none">
					      <td class="text_left">追加項目：</td>
					      <td>
					      		項目値段：
					      		<select name="extraPrice" style="width:150">
						           	<option value="0">選択してください</option>
									${Utility::Option(Utility::OptionArray($extraPrices, 'id', 'name'), $order['extra_price'])}
					        	</select>
					        	項目数：
					        	<select name="extraAmount" style="width:150">
						           	<option value="0">選択してください</option>
									${Utility::Option(Utility::OptionArray($extraAmounts, 'id', 'name'), $order['extra_amount'])}
						        </select>
					      </td>
					      <td>
					      </td>
					    </tr>
					    
					    <tr>
					      <td class="text_left">設備：</td>
					      <td>
					      	<select id="designationStuff" name="device_id" style="width:150">
					           	<option value="0">選択してください</option>
								${Utility::Option(Utility::OptionArray($deviceList, 'id', 'device_name'), $deviceId)}
								<option value="99999">Ghost(Designed For Special)</option>
					        </select>
					       </td>
					      <td>&nbsp;</td>
					    </tr>
					    <tr>
					      <td class="text_left">予約終了時間：</td>
					      <td>
					      	<!--{if $order != null }-->
					      	<input type="text" id="end_time" name="endHour" size="2" readonly="readonly" value="${date("H", $order['service_end_time']) * 1}"/>
					      	<input type="text" id="end_time" name="endMinute" size="2" readonly="readonly" value="${date("i", $order['service_end_time']) * 1}"/>
					      	<!--{else}-->
					      	<input type="text" id="end_time" name="endHour" size="2" readonly="readonly" value="${date("H") * 1}"/>
					      	<input type="text" id="end_time" name="endMinute" size="2" readonly="readonly" value="${date("i") * 1}"/>
					      	 <!--{/if}-->
					      </td>
					      <td></td>
					    </tr>
							
						</tbody>
						</table>
					</div>
					<p class="bottom_m"><input type="submit" class="button" value="登録" /></p>
					<p class="bottom_m"><a href="{$_SERVER['HTTP_REFERER']}">戻る</a></p>
					<div style="display:none">
						<table>
							<tr>
								<td colspan="7">
									<div class="pagination"> 
										<a href="#" title="First Page">&laquo; First</a>
										<a href="#" title="Previous Page">&laquo; Previous</a> 
										<a href="#" class="number" title="1">1</a> 
										<a href="#" class="number" title="2">2</a> 
										<a href="#" class="number current" title="3">3</a>
										 <a href="#" class="number" title="4">4</a> 
										 <a href="#" title="Next Page">Next &raquo;</a>
										 <a href="#" title="Last Page">Last &raquo;</a> </div>
									<!-- End .pagination -->
									<div class="clear"></div>
								</td>
							</tr>
						</table>
					</div>
				</div>
				</form>
			</div>
			<!-- End .content-box-content -->
		</div>

		<!-- End .content-box -->
		<!-- End .content-box -->
		<!-- End .content-box -->
		<div class="clear"></div>
		<!-- Start Notifications -->
		<!-- End Notifications -->
		<div id="footer"> <small>
			<!-- Remove this notice or replace it with whatever you want -->

			&#169; Copyright 2011 川崎エステ　エレガントリゾート　すべての女性を美しく幸せに | Powered by <a href="#">ZHONGHUA</a> | <a href="#">Top</a> </small> </div>
		<!-- End #footer -->
	</div>
	<!-- End #main-content -->
</div>

</body>
<!-- Download From www.exet.tk-->
</html>


<script type="text/javascript"> 
var serviceCache = [];
var timeError = false;
var staffError = false;
var userError = false;
var tempCalendar = null;
$(document).ready(function(){

		

		if( $("#searchUser").length > 0 ){
			$("#searchUser").bind("click", function(e){
				$("#searchUser").next("span").remove();
				$.get("{$webRoot}/service/searchUser.php", "email=" + $("input[name='email']").val(), function(data){
					if( data.error != 0 ){
						alert("ユーザ見つかりませんでした。");
						return ;
					}
					$("input[name='user_id']").val( data.data['id'] );
					$("#searchUser").after("<span>" + data.data['family_name'] + data.data['personal_name'] + "</span>");
				}, "json");
			})
		}
	
	$("#testForm").bind("submit", function(){
		if(staffError == true){
			$("#staff_error").html("ご指名スタッフはこの時間で予約取れませんの為に、ご予約できませんでした。").show();
			return false;
		}else{
			$("#staff_error").html("").hide();
		}
		return !timeError
		
	})
	
	$("input[name='start_date']").bind("blur", function(){
		calTime();
		getStaffs();
	})
	$("input[name='startMinute']").bind("blur", function(){
		calTime();
		getStaffs();
	})
	
	$("select[name='shopId']").bind("change", function(){
		if( $(this).val() < 1 ){
			return ;
		}
		$.get("{$webRoot}/ajax/GetServiceList.php", "shopId=" + $(this).val(), function(data){
			var options = '<option value="0">選択してください</option>';
			for(var index in data.data){
				if( !index ){
					continue;
				}
				options = options + '<option value="' + index + '">' + data.data[index].service_name + '</option>';
				serviceCache[index] = data.data;
			}
			$("select[name='service_id']").html(options);
		}, "json");
		
	});


	$("select[name='service_id']").bind("change", function(){
		calTime();
		getStaffs();
		
	});
	
	triggerExtra();
});


function getStaffs(){
	if( $("select[name='shopId']").val() < 1 || $("input[name='startHour']") < 1 || $("select[name='service_id']").val() < 1){
		return ;
	}
	var data = "shopId=" + $("select[name='shopId']").val() + "&serviceId=" +$("select[name='service_id']").val();
	data = data + "&startHour=" + $("input[name='startHour']").val() + "&startMinute=" + $("input[name='startMinute']").val() + 
		"&endHour=" + $("input[name='endHour']").val() + "&endMinute=" + $("input[name='endMinute']").val();
	data = data + "&start_date=" + $("input[name='start_date']").val();
	data = data + "&id=" + $("input[name='id']").val();
	$.get("{$webRoot}/ajax/GetStaffList.php", data, function(data){
		if( data.error != 0 ){
			$("select[name='staff_id']").html('<option value="0">選択してください</option>');
			staffError = true;
			return ;
		}
		staffError = false;
		$("#staff_error").hide();
		var options = '<option value="0">選択してください</option>';
		for(var index in data.data){
			if( !index ){
				continue;
			}
			options = options + '<option value="' + index + '">' + data.data[index] + '</option>';
			serviceCache[index] = data.data;
		}
		$("select[name='staff_id']").html(options);
	}, "json");
}


function calTime(){
	
	var data = "shopId=" + $("select[name='shopId']").val() + "&serviceId=" +$("select[name='service_id']").val();
	data = data + "&startHour=" + $("input[name='startHour']").val() + "&startMinute=" + $("input[name='startMinute']").val();
	data = data + "&start_date=" + $("input[name='start_date']").val();
	data = data + "&id=" + $("input[name='id']").val();
	$.get("{$webRoot}/ajax/CalcEndTime.php", data, function(data){
		if( data.error == 0 ){
			$("#timeError").hide();
			timeError = false;
			for(var index in data.data){
				$("input[name='endHour']").val(data.data['endHour']);
				$("input[name='endMinute']").val(data.data['endMinute']);
			}
		}else{
			$("#timeError").html(data.data).show();
			timeError = true;
		}
		
	}, "json");
}

function triggerExtra(){
	$("input[name='addExtra']").bind("click", function(){
		if($(this).attr("checked") == true || $(this).attr("checked") == "true"){
			$("#extraParts").show();
		}else{
			$("#extraParts").hide();
		}
	});
}

</script> 
</html> 
